package modules.user.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import entity.User;
import modules.user.service.IUserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 用户控制类
 * @author ziv
 * @date 2018-12-08
 */
@Controller
@RequestMapping(value = "/user")
public class UserController {
    @Resource
    private IUserService userService;

    @RequestMapping(value = "/showUser")
    public void showUser (HttpServletRequest request, HttpServletResponse response) throws IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        int userID = Integer.parseInt(request.getParameter("userID"));
        User user = userService.getByUserId(userID);
        ObjectMapper mapper = new ObjectMapper();
        response.getWriter().write(mapper.writeValueAsString(user));
        response.getWriter().close();
    }
}
